package com.rech.xbexpress3;


import android.os.AsyncTask;
import android.os.Message;
import android.util.Log;

import com.rech.utils.CommandUtil;
import com.rech.utils.OtherUtil;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import redis.clients.jedis.Jedis;

import static android.content.ContentValues.TAG;
public class RedisWorker {
    public String host;
    public int port=6379;
    public String pass;
    public static Jedis jedis;
    public String uid;
    private static boolean TestFlag;
    public RedisWorker(String arghost,int argport,String argpass,String arguid){
        this.host = arghost;
        this.port = argport;
        this.pass = argpass;
        this.uid = arguid;
        this.jedis = new Jedis(host, port);
        //this.jedis = new Jedis(host, port, 100000);
        jedis.auth(pass);
    }
    public void start () {
        if (RedisLogic.getInstance().redisWorking == false) {
            //jedis.ping();
            RedisLogic.getInstance().redisWorking = true;
        }
    }

    /*获取连接的方法*/
    public static Jedis getJedis(){
        return jedis;
    }

    /*@Override
    public void run() {
        String result;

        try{

            result = jedis.lpop(uid);
        }
        catch (Exception e){
            result = null;
        }
        while(RedisLogic.getInstance().redisWorking == true){
            try{
                if(result != null){
                    //recvBuffer.add(result);
                    RedisLogic.getInstance().doWorker(result);
                    Message msg = new Message();
                    msg.what = 9999;
                    msg.obj = "正常" + OtherUtil.getTime();
                    EventBus.getDefault().post(msg);
                    TestFlag = true;
                }
            }catch (Exception e){

            }
            try{
                Thread.sleep(500);

                Message msg = new Message();
                msg.what = 6666;
                msg.obj = "redis读取中";
                EventBus.getDefault().post(msg);

                result = jedis.lpop(uid);

                msg.what = 5555;
                if (null == result) {
                    msg.obj = "redis内容为null" + OtherUtil.getTime();
                } else {
                    msg.obj = "redis内容不为null" + OtherUtil.getTime();
                }
                EventBus.getDefault().post(msg);
            }catch (Exception e){
                //Log.d(TAG,e.toString());
                result = null;

                if (TestFlag) {
                    Message msg = new Message();
                    msg.what = 9999;
                    msg.obj = "为空" + OtherUtil.getTime() + e.toString();
                    EventBus.getDefault().post(msg);
                    TestFlag = false;
                }

            }
        }
    }*/
}
